# -*- coding: utf-8 -*-

from wechatpy import WeChatOAuth

from mpdev.wechat_token import APPID, APPSECRET, TOKEN
OAUTH_REDIRECT_URL = 'http://www.guanjia.group/oauth2/gzone'
OAUTH_SCOPE = 'snsapi_userinfo'
OAUTH_STATE = '1'


class WeChat:
    def __init__(self, app=None):
        self.app = None
        self.oauth = None

        if app is not None:
            self.init_app(app)

    def init_app(self, app):
        self.oauth = WeChatOAuth(
            app_id=APPID,
            secret=APPSECRET,
            redirect_uri=OAUTH_REDIRECT_URL,
            scope=OAUTH_SCOPE,
            state=OAUTH_STATE
        )
        app.oauth = self.oauth
        self.app = app
